# import necessary packages
import cv2 as cv
import argparse

# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i","--image",required=True,help="The Path to Image")
args = vars(ap.parse_args())

# load the image and convert it to grascale
image = cv.imread(args["image"])
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)

# construct a rectangular kernel and apply a blackhat operation which
# enables us to find dark regions on a light background
rectKernel = cv.getStructuringElement(cv.MORPH_RECT,(13,5))
blackHat = cv.morphologyEx(gray,cv.MORPH_BLACKHAT,rectKernel)

# similarly, a tophat (also called a "whitehat") operation will enable
# us to find light regions on a dark background
topHat = cv.morphologyEx(gray,cv.MORPH_TOPHAT,rectKernel)

# show the output images
cv.imshow("Original",image)
cv.imshow("BlackHat",blackHat)
cv.imshow("WhiteHat",topHat)
cv.waitKey(0)
